package com.huiyuan.controller;

import com.huiyuan.common.PageVo;
import com.huiyuan.common.Result;
import com.huiyuan.feign.BikeService;
import com.huiyuan.feign.MemberService;
import com.huiyuan.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author huiyuan080
 * @data 2023/5/3
 * @apiNote
 */
@RestController
@RequestMapping("/order-service/order")
public class OrderController {

    @Autowired
    private OrderService orderService;



    /**
     * 添加订单
     *
     * @param userId
     * @param bicycleId
     * @return
     */
    @PostMapping("useBicycle")
    public Result useBicycle(Integer userId, Integer bicycleId) {
        int i = orderService.useBicycle(userId, bicycleId);
        if (i == 1) {
            return new Result();
        } else if (i == 2) {
            return new Result("当前车辆不可用");
        } else {
            return new Result("用户已经租车");
        }
    }


    /**
     * 分页查询会员用车的记录
     *
     * @return
     */
    @GetMapping("getMemberOrder")
    public Result getMemberOrder(Integer pageNumber, Integer pageSize, Integer userId) {
        PageVo page = new PageVo();
        page.setPageNumber(pageNumber);
        page.setPageSize(pageSize);
        page = orderService.getMemberOrder(page, userId);
        return new Result(page);
    }


    /**
     * 会员锁车还车
     * @param userId
     * @param id
     * @return
     */
    @GetMapping("backBicycle")
    public Result backBicycle(Integer userId, Integer id) {
       int i =  orderService.backBicycle(userId, id);
        return new Result();
    }

}
